﻿using System;

namespace Json
{
  public class JsonNameAttribute:Attribute
  {
    public JsonNameAttribute(string name)
    {
      Name = name;
    }

    private string _name;
    public string Name
    {
      get { return _name; }
      protected set
      {
        if (value.Contains("\""))
          throw new JsonException("Name cannot contain '\"' inside Name attribute");

        if (value.Contains("."))
          throw new JsonException("Name cannot contain '.' inside Name attribute");

        if (value.Contains("["))
          throw new JsonException("Name cannot contain '[' inside Name attribute");

        if (value.Contains("]"))
          throw new JsonException("Name cannot contain ']' inside Name attribute");

        _name = value;
      }
    }
  }
}
